unit SampleCommon;

interface

uses
  System.SysUtils,
  DIrr, DIrr.Types;

function DriverChoiceConsole(AllDrivers: Boolean = True): E_DRIVER_TYPE;

implementation

function DriverChoiceConsole(AllDrivers: Boolean = True): E_DRIVER_TYPE;
const
  DRV_NAMES: array[0..5] of String =
  (
    'NullDriver', 'Software Renderer', 'Burning''s Video', 'Direct3D 8.1', 'Direct3D 9.0c', 'OpenGL 1.x/2.x/3.x'
  );
var
  i: U32;
  c: Char;
begin
  Writeln('Please select the driver you want:');
  i := Ord(EDT_COUNT);
  while i > 0 do
  begin
    if AllDrivers or IsSupportedDriver(E_DRIVER_TYPE(i - 1)) then
      Writeln(Format(' (%s) %s', [Char((Ord('a') + Ord(EDT_COUNT) - i)), DRV_NAMES[i - 1]]));
    Dec(i);
  end;

  Readln(c);
  c := Char(Ord(EDT_COUNT) + Ord('a') - Ord(c));

  for i := Ord(EDT_COUNT) downto 1 do
  begin
    if not (AllDrivers or (IsSupportedDriver(E_DRIVER_TYPE(i - 1)))) then
    begin
      c := Char(Ord(c) - 1);
    end;

    if i = Ord(c) then
    begin
      Result := E_DRIVER_TYPE(i - 1);
      Exit;
    end;
  end;

  Result := EDT_COUNT;
end;

end.
